package com.example.haohao.myview;

import com.example.middle_connect.dealInterface;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class MirrorReflect {

    public static String ToInvoke_Mirror_Sleep() {
        try {
            Class clz = Class.forName("com.example.vpdemo.Mirror");
            Method method = clz.getDeclaredMethod("sleep", String.class);
            method.setAccessible(true);//解除私有限定
            Constructor constructor = clz.getDeclaredConstructor();
            Object object = constructor.newInstance();
            String resultS = (String) method.invoke(object, "");
            return resultS;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String ToInvoke_Mirror_cal(int a, int b, dealInterface ideal) {
        try {
            Class clz = Class.forName("com.example.vpdemo.Mirror");
            Method method = clz.getDeclaredMethod("cal_add", int.class, int.class, dealInterface.class);
            method.setAccessible(true);//解除私有限定
            Constructor constructor = clz.getDeclaredConstructor();
            constructor.setAccessible(true);//暴力反射
            Object object = constructor.newInstance();
            method.invoke(object, a, b, ideal);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
